<ui:composition  xmlns="http://www.w3.org/1999/xhtml"
                 xmlns:h="http://java.sun.com/jsf/html"
                 xmlns:f="http://java.sun.com/jsf/core"
                 xmlns:ui="http://java.sun.com/jsf/facelets"
                 xmlns:p="http://primefaces.org/ui"
                 xmlns:xc="http://java.sun.com/jsf/composite/xpert/components"
                 xmlns:x="http://xpert.com/faces">

    Xpert-framework must get EntityManager, so create a class that implements <b>com.xpert.EntityManagerFactory</b> and define it in <b>xpert-config.xml</b> (must be located in WEB-INF)
    
    <br/>
    This factory is used in <h:link outcome="/views/components/initializer.jsf" value="initializer"/>, <h:link outcome="/views/components/findAllBean.jsf" value="FindAllBean"/>
    and  <h:link outcome="/views/audit/auditing.jsf" value="audit"/> components.
    <pre name="code" class="xml">
    &lt;xpert-config xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;
        &lt;entity-manager-factory&gt;com.xpert.showcase.dao.EntityManagerFactoryImpl&lt;/entity-manager-factory&gt;
    &lt;/xpert-config&gt;    
    </pre>

    Here is the <b>EntityManagerFactory</b> of this showcase

    <pre name="code" class="java">
        import com.xpert.EntityManagerFactory;
        import java.util.logging.Level;
        import java.util.logging.Logger;
        import javax.naming.InitialContext;
        import javax.naming.NamingException;
        import javax.persistence.EntityManager;

        public class EntityManagerFactoryImpl implements EntityManagerFactory {

            private static final Logger logger = Logger.getLogger(EntityManagerFactoryImpl.class.getName());
            private static final String ENTITY_MANAGER_REF_NAME = &quot;java:comp/env/persistence/entityManager&quot;;

            @Override
            public EntityManager getEntityManager() {
                InitialContext ctx;
                try {
                    ctx = new InitialContext();
                    EntityManager entityManager = (EntityManager) ctx.lookup(ENTITY_MANAGER_REF_NAME);
                    return entityManager;
                } catch (NamingException ex) {
                    logger.log(Level.SEVERE, null, ex);
                } catch (Exception ex) {
                    logger.log(Level.SEVERE, null, ex);
                }
                return null;
            }
        }
    </pre>

    Using persistence-unit (xpertShowcasePU), the EntityManager can be get this way in <b>web.xml</b>:
    <br/>Remember that <b>persistence.xml</b> must be visible to the module of this configuration.
    <pre name="code" class="xml">
        &lt;persistence-context-ref&gt;
            &lt;persistence-context-ref-name&gt;persistence/entityManager&lt;/persistence-context-ref-name&gt;
            &lt;persistence-unit-name&gt;xpertShowcasePU&lt;/persistence-unit-name&gt;
        &lt;/persistence-context-ref&gt;
    </pre>
</ui:composition>
